/**
 * @author:albert
 */

package com.bkbw.live.battle.business;

import java.util.HashMap;

import javax.management.Query;

import com.bkbw.live.battle.database.DatabaseManager;
import com.bkbw.live.battle.database.bean.BuildBean;
import com.bkbw.live.common.dataproto.EnumConfigPb.BuildType;

public class BuildingConf {
	public static BuildingConf instance;
	
	public static BuildingConf getInstance() {
		if (instance == null) {
			instance = new BuildingConf();
			//instance.items.put(BuildType.Wall, new BuildingItem(BuildType.Wall, new int[] {0, 0}));
			//instance.items.put(BuildType.Furniture, new BuildingItem(BuildType.Wall, new int[] {0, 0, 0, 1, 1, 0, 1, 1}));
			//DatabaseManager.getInstance().getBuildTable().getBeanByKey(key);
			
			for (BuildBean bean : DatabaseManager.getInstance().getBuildTable().getTable().values()) {
				//int[][] = new int[][];
				int[] array = new int[bean.getWidth() * bean.getHeight() * 2];
				for (int z = 0; z < bean.getHeight(); ++z){
					for (int x = 0; x < bean.getWidth(); ++x) {
						array[(z * bean.getWidth() + x) * 2] = x;
						array[(z * bean.getWidth() + x) * 2 + 1] = z;
					}
				}
				System.out.println("building data start ");
				for (int i = 0; i < array.length; i++) {
					System.out.print(" " + array[i]);
				}
				System.out.println("\nbuilding data end ");
				instance.items.put(bean.getId(), new BuildingItem(bean.getId(), array));
				//instance.items.put(bean.getId(), new BuildingItem(BuildType.Wall, new int[] {0, 0}))
			}
		}
		return instance;
	}
	
	protected HashMap<Integer, BuildingItem> items = new HashMap<Integer, BuildingConf.BuildingItem>();
	
	public BuildingItem queryItem(BuildType buildType){
		if (items.containsKey(buildType)) {
			return items.get(buildType);
		}
		return null;
	}
	
	//public int[] queryItemData(BuildType buildType){
	public int[] queryItemData(int buildId){
		if (items.containsKey(buildId)) {
			return items.get(buildId).getData();
		}
		return null;
	}
	
	public static class BuildingItem {
		protected int[] data;
		public int[] getData() {
			return data;
		}
		
		protected int buildId;
		public int getBuildId() {
			return buildId;
		}
		
		public BuildingItem(int buildId, int[] data) {
			this.buildId = buildId;
			this.data = data;
		}
	}
	
	
	
}
